package pnu.ssm.tmp;
/*package pnu.ssm.sbchild;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;

import pnu.ssm.chinese.ChineseHelper;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class SavedChoiceActivity extends Activity {
	public static final String TAG = "ChoiceActivity";

	public static final int CHOICE_ACTIVITY = 1;
	public static final int SUCCESS = 2;
	public static final int FAIL = 3;

	public static final String Path = "Path";
	public static final String Count = "Count";
	public static final String Answer = "Answer";
	public static final String NoAnswer1 = "NoAnswer1";
	public static final String NoAnswer2 = "NoAnswer2";
	public static final String NoAnswer3 = "NoAnswer3";

	private AssetManager assets;

	private Button btn_test;
	private OnTouchListener touchListener = new OnTouchListener() {
		private final int START_DRAG = 0;
		private final int END_DRAG = 1;
		private int isMoving;
		private float offset_x, offset_y;
		private boolean start_yn = true;
		
		@Override
		public boolean onTouch(View v, MotionEvent event) {
			int eventAction = event.getAction();
			
			if (eventAction == MotionEvent.ACTION_DOWN) {
				if (start_yn) {
					offset_x = event.getRawX();
					offset_y = event.getRawY();
					start_yn = false;
				}
				isMoving = START_DRAG;
			} else if (eventAction == MotionEvent.ACTION_UP) {
				isMoving = END_DRAG;
			} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
				if (isMoving == START_DRAG) {
					v.setX((int) event.getRawX() - offset_x);
					v.setY((int) event.getRawY() - offset_y);
				}
			}
			return false;
		}
	};

	CheckBox choic_checkbox1;
	CheckBox choic_checkbox2;
	CheckBox choic_checkbox3;
	CheckBox choic_checkbox4;

	ImageView bitmaplv;

	TextView choic_text1;
	TextView choic_text2;
	TextView choic_text3;
	TextView choic_text4;

	SharedPreferences pref;
	SharedPreferences.Editor editor;

	ArrayList<String> randomList = new ArrayList<String>();
	final int[] arr = new int[4];

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_choice);

		assets = getResources().getAssets();

		pref = getPreferences(MODE_PRIVATE);
		editor = pref.edit();

		Intent intent = getIntent();
		String path = intent.getStringExtra(Path);
		int count = intent.getIntExtra(Count, 0);
		String answer = intent.getStringExtra(Answer);
		String noAnswer1 = intent.getStringExtra(NoAnswer1);
		String noAnswer2 = intent.getStringExtra(NoAnswer2);
		String noAnswer3 = intent.getStringExtra(NoAnswer3);

		btn_test = (Button)findViewById(R.id.button1);
		btn_test.setOnTouchListener(touchListener);

		// list에 문자열 대입
		randomList.add(answer);
		randomList.add(noAnswer1);
		randomList.add(noAnswer2);
		randomList.add(noAnswer3);

		Bitmap bitmap = loadBitmap(path, count);
		bitmaplv = (ImageView) findViewById(R.id.iv_choice_problem);
		bitmaplv.setImageBitmap(bitmap);

		// xml과 연결
		choic_text1 = (TextView) findViewById(R.id.tv_answer1);
		choic_text2 = (TextView) findViewById(R.id.tv_answer2);
		choic_text3 = (TextView) findViewById(R.id.tv_answer3);
		choic_text4 = (TextView) findViewById(R.id.tv_answer4);

		//랜덤함수 생성
		Random random = new Random();

		for (int i = 0; i < arr.length; i++) {
			arr[i] = random.nextInt(4);
			for (int j = 0; j < i; j++) {
				if (arr[i] == arr[j])
					i--;
			}
		}

		//텍스트뷰에 글자 적어 줌
		choic_text1.setText(randomList.get(arr[0]));
		choic_text2.setText(randomList.get(arr[1]));
		choic_text3.setText(randomList.get(arr[2]));
		choic_text4.setText(randomList.get(arr[3]));

		//체크박스 연결
		choic_checkbox1 = (CheckBox) findViewById(R.id.cb_answer1);
		choic_checkbox1.setOnCheckedChangeListener(listener);
		choic_checkbox2 = (CheckBox) findViewById(R.id.cb_answer2);
		choic_checkbox2.setOnCheckedChangeListener(listener);
		choic_checkbox3 = (CheckBox) findViewById(R.id.cb_answer3);
		choic_checkbox3.setOnCheckedChangeListener(listener);
		choic_checkbox4 = (CheckBox) findViewById(R.id.cb_answer4);
		choic_checkbox4.setOnCheckedChangeListener(listener);
		Log.d(TAG, "ok done.");
	}


	public OnCheckedChangeListener listener = new OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(CompoundButton c, boolean isChecked) {
			if(isChecked){
				switch(c.getId())
				{
				case R.id.cb_answer1:
					choic_checkbox1.setChecked(true);
					choic_checkbox2.setChecked(false);
					choic_checkbox3.setChecked(false);
					choic_checkbox4.setChecked(false);
					if(arr[0] == 0){
						setResult(ChoiceActivity.SUCCESS);
					}else{
						setResult(ChoiceActivity.FAIL);
					}
					finish();
					break;
				case R.id.cb_answer2:
					choic_checkbox1.setChecked(false);
					choic_checkbox2.setChecked(true);
					choic_checkbox3.setChecked(false);
					choic_checkbox4.setChecked(false);

					if(arr[1] == 0){
						setResult(ChoiceActivity.SUCCESS);
					}else{
						setResult(ChoiceActivity.FAIL);
					}
					break;
				case R.id.cb_answer3:
					choic_checkbox1.setChecked(false);
					choic_checkbox2.setChecked(false);
					choic_checkbox3.setChecked(true);
					choic_checkbox4.setChecked(false);

					if(arr[2] == 0){
						setResult(ChoiceActivity.SUCCESS);
					}else{
						setResult(ChoiceActivity.FAIL);
					}
					break;
				case R.id.cb_answer4:
					choic_checkbox1.setChecked(false);
					choic_checkbox2.setChecked(false);
					choic_checkbox3.setChecked(false);
					choic_checkbox4.setChecked(true);

					if(arr[3] == 0){
						setResult(ChoiceActivity.SUCCESS);
					}else{
						setResult(ChoiceActivity.FAIL);
					}
					break;
				default :
					Log.e(TAG, "switch error");
					break;
				}
				finish();
			}
		}
	};

	public Bitmap loadBitmap(String path, int count) {
		String bitmapPath = "level8/" + path + "/";
		String filePath = bitmapPath + count + ".bmp";
		Bitmap bitmap = null;
		try {
			bitmap = BitmapFactory.decodeStream(assets.open(filePath));
		} catch (IOException e) {
			e.printStackTrace();
		}
		if(bitmap == null) {
			Log.e(TAG, "fail to load bitmap. path error");
			return bitmap;
		}
		int viewWidth = ChineseHelper.DEVICE_WIDTH;
		float width = bitmap.getWidth();
		float height = bitmap.getHeight();

		float percente = width / 100;
		float scale = viewWidth / percente;
		width *= (scale / 100);
		height *= (scale / 100);

		Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap,
				(int) width, (int) height, false);

		return scaledBitmap;
	}
}
*/